//
//  KLButton.m
//  used
//
//  Created by xalo on 16/7/13.
//  Copyright © 2016年 王凯. All rights reserved.
//

#import "KLButton.h"
#import <UIButton+WebCache.h>


@implementation KLButton

- (void)setup
{
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.titleLabel.font = [UIFont systemFontOfSize:12];
    [self setBackgroundImage:[UIImage imageNamed:@"mainCellBackground"] forState:UIControlStateNormal];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

- (void)awakeFromNib
{
    [self setup];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 调整图片
    self.imageView.y = 7;
    self.imageView.width = self.width * 0.6;
    self.imageView.height = self.imageView.width;
    self.imageView.x = self.width * 0.25;
    
    // 调整文字
    self.titleLabel.x = 0;
    self.titleLabel.y = CGRectGetMaxY(self.imageView.frame);
    self.titleLabel.width = self.width;
    self.titleLabel.height = self.height - self.titleLabel.y;
}

- (void)setCateModel:(DZZScrollViewModel *)cateModel {
    
    _cateModel = cateModel;
    [self setTitle:cateModel.title forState:UIControlStateNormal];
    // 利用SDWebImage给按钮设置image
    [self sd_setImageWithURL:[NSURL URLWithString:cateModel.app_picpath] forState:UIControlStateNormal];
}

- (void)setModel:(DZZRecommedModel *)cateModel{
    _recomed = cateModel;
    [self setTitle:cateModel.name forState:UIControlStateNormal];
    [self sd_setImageWithURL:[NSURL URLWithString:cateModel.coverPic] forState:UIControlStateNormal];
    
}

@end
